package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.Result;
import io.renren.dao.SmallCanteenPurchasemxDao;
import io.renren.dto.SmallCanteenPurchasemxDTO;
import io.renren.entity.SmallCanteenPurchasemxEntity;
import io.renren.service.SmallCanteenPurchasemxService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 小食堂采购明细表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Service
public class SmallCanteenPurchasemxServiceImpl extends CrudServiceImpl<SmallCanteenPurchasemxDao, SmallCanteenPurchasemxEntity, SmallCanteenPurchasemxDTO> implements SmallCanteenPurchasemxService {
     @Autowired
     private SmallCanteenPurchasemxDao smallCanteenPurchasemxDao;

    @Override
    public QueryWrapper<SmallCanteenPurchasemxEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<SmallCanteenPurchasemxEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public List<SmallCanteenPurchasemxDTO> selectGyss(Long id) {
        return smallCanteenPurchasemxDao.seletGys(id);
    }
    @Override
    public List<SmallCanteenPurchasemxDTO> selectGyss2(Long id) {
        return smallCanteenPurchasemxDao.seletGys2(id);
    }

    @Override
    public List<SmallCanteenPurchasemxDTO> selectFoods(long id,long ids) {
        return smallCanteenPurchasemxDao.seletGysFood(id,ids);
    }

    @Override
    public List<SmallCanteenPurchasemxDTO> seletGysFood1(long id, long ids) {

        return  smallCanteenPurchasemxDao.seletGysFood1(id,ids);
    }

    @Override
    public void deleteOrder(Long dto) {
        smallCanteenPurchasemxDao.deleteOrder(dto);
    }

    @Override
    public void updateUnitPrice(SmallCanteenPurchasemxDTO dto){
        dto.setSubStatus(1);
        update(dto);
    }

    @Override
    public Result updatePhoto(SmallCanteenPurchasemxDTO dto){
        SmallCanteenPurchasemxDTO purchasemxDTO = smallCanteenPurchasemxDao.gysMx(dto.getSmallCanteenPurchasemxId());
        if(0 != purchasemxDTO.getSubStatus()){
            dto.setStatus(4);
            dto.setSubStatus(1);
            update(dto);
         return new Result();
        }else {
        Result result = new Result();
        result.setCode(5000);
        result.setMsg("供应商未报价，不能审核");
        return result;
    }

    }

    @Override
    public void updateOrder1(long id, long subStutas) {
        smallCanteenPurchasemxDao.updateOrder1(id,subStutas);
    }

    @Override
    public void updateOrder2(long orderId, long foodId,float purchaseNum) {
      smallCanteenPurchasemxDao.updateOrder2(orderId,foodId,purchaseNum);
    }

    @Override
    public void delectOrder(long orderId, long foodId) {
        smallCanteenPurchasemxDao.delectOrder(orderId,foodId);
    }
}